package com.qingke.beSuper2.command;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

import com.qingke.beSuper2.command.CommandFactory.CommandCode;
import com.qingke.beSuper2.command.impl.AskCommand;
import com.qingke.beSuper2.command.impl.ExitCommand;
import com.qingke.beSuper2.command.impl.HelpCommand;
import com.qingke.beSuper2.command.impl.LoginCommand;
import com.qingke.beSuper2.pojo.Player;

public class PlayerCommandFactory extends SystemCommandFactory {

	private Player player;
	
	public PlayerCommandFactory (Player player) {
		this.player = player;
	}
	
	private static Map<CommandCode, Class<? extends Command>> commandMap = 
			new HashMap<>();
	
	static {
		commandMap.put(CommandCode.ASK, AskCommand.class);
		
		
	}
	@Override
	public Command buildCommand(CommandCode cmd) {
		Class<? extends Command> CommandName = commandMap.get(cmd);
		if(CommandName == null){
			return super.buildCommand(cmd);
		}
		Constructor<? extends Command> cons;
		try {
			cons = CommandName.getConstructor(Player.class);
			Command c =  cons.newInstance(player);
			return c;
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
			
		
		return null;
	}

}
